<template>
	<view class="store-upgrade-upload-layout" @tap="upload">
		<image class="store-upgrade-upload-img" :src="imageUrl || '/static/home/upload_image@2x.png'" mode="scaleToFill"></image>
		<text class="store-upgrade-upload-text">{{title}}</text>
	</view>
</template>

<script setup>
	const props = defineProps({
		/**
		 * 标题
		 */
		title:{
			type:String,
			default:'点击上传'
		},
		/**
		 * ocr识别类型，默认为空字符串不调用ocr功能
		 * idcard_front：身份证正面
		 * idcard_back：身份证反面
		 * bankcard：银行卡
		 * business_license：营业执照
		 */
		ocrType:{
			type:String,
			default:''
		}
	})
	const imageUrl = defineModel()
	const emits = defineEmits(['uploadResult'])
	//上传图片
	const upload = async ()=>{
		const url = await uni.$utils.uploadImage()
		imageUrl.value = url
		if(props.ocrType != ''){
			const ocrRes = await uni.$utils.getImageOcrInfo(url, props.ocrType)
			emits('uploadResult',ocrRes)
		}
	}
	
</script>

<style lang="scss" scoped>
.store-upgrade-upload-layout{
	display: flex;
	flex-direction: column;
	align-items: center;
	background-color: #ffffff;
	flex: 1;
	.store-upgrade-upload-img{
		width: 100%;
		height: 190rpx;
	}
	.store-upgrade-upload-text{
		font-size: 26rpx;
		margin-top: 10rpx;
	}
}
</style>